{% extends 'index.html' %}

{% block title %}仓库页{% endblock %}

{% block content_main %}
{% load static %}
{% load custom_filters %}
<script src="{% static 'js/warehouse.js' %}"></script>
<script>
    var csrfToken = "{{ csrf_token }}";
</script>
<div class="mt-1 m-4 pt-1">
    <!-- 隐藏的文件选择框 -->
    <input type="file" id="file-input" style="display: none;" onchange="handleFileChange(event)">

    <div class="card mt-1">
        <div class="card-header">功能区</div>
        <div class="card-body" id="function-area">
            <button type="button" class="btn btn-primary" id="select-file-button">上传文件</button>
            <button type="button" class="btn btn-primary" onclick="function_area('refresh_data')">刷新数据</button>
            <button type="button" class="btn btn-primary" onclick="function_area('delete_data')">清空数据</button>
            <button type="button" class="btn btn-primary" onclick="function_area('delete_cache')">清空缓存</button>
        </div>
    </div>
    <div class="card mt-1">
        <div class="card-header">策略卡包及金融数据获取</div>
        <div class="card-body">
            <p class="lead text-center mt-4">
                请点击<a href="https://lq1zajnpdfm.feishu.cn/drive/folder/YvJQfPOqflbCNtdhT7Ccypelnqh" target="_blank">公开数据包</a>免费获取金融数据，获取定制金融数据及最新策略卡包请点击<a href="https://gitee.com/benhe256/ddquant-x/blob/master/README.md" target="_blank">【社群】</a>，如遇问题请联系作者（微信：YHDBank）。
            </p>
        </div>
    </div>
    <div class="card mt-1">
        <div class="card-header">全部战法</div>
        <!-- MkData表格，包含分页和多选功能 -->
        <form class="card-body" id="tactic-form" method="post">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>描述</th>
                        <th>类别</th>
                        <th>因子</th>
                        <th>类名</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in tactic_s %}
                        <tr>
                            <td>{{ item.name }}</td>
                            <td>{{ item.describe }}</td>
                            <td>{{ item.tactic_type }}</td>
                            <td>{{ item.factor_name }}</td>
                            <td>{{ item.class_name }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>

            <!-- 分页导航 -->
            <div class="pagination">
                {% if tactic_s.has_previous %}
                    <a href="?page_tactic=1" style="margin: 5px;">第一页</a>
                    <a href="?page_tactic={{ tactic_s.previous_page_number }}" style="margin: 5px;">上一页</a>
                {% endif %}

                <span style="margin: 5px;">第{{ tactic_s.number }}页，共{{ tactic_s.paginator.num_pages }}页</span>

                {% if tactic_s.has_next %}
                    <a href="?page_tactic={{ tactic_s.next_page_number }}" style="margin: 5px;">下一页</a>
                    <a href="?page_tactic={{ tactic_s.paginator.num_pages }}" style="margin: 5px;">最后</a>
                {% endif %}
            </div>
            <!-- 确认按钮 -->
            <button class="d-none" type="submit" style="margin-left: 10px; border: 1px solid #ccc;border-radius: 5px;cursor: pointer;">确认</button>
        </form>
    </div>

    <div class="card mt-1">
        <div class="card-header">全部数据</div>
        <!-- MkData表格，包含分页和多选功能 -->
        <form class="card-body" id="data-form" method="post">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>文件名</th>
                        <th>周期</th>
                        <th>最后修改时间</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>数量</th>
                        <th>标的</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in data_s %}
                        <tr>
                            <td>{{ item.name }}</td>
                            <td>{{ item.interval }}</td>
                            <td>{{ item.data_modified_time|local_time }}</td>
                            <td>{{ item.start_time|local_time }}</td>
                            <td>{{ item.end_time|local_time }}</td>
                            <td>{{ item.number }}</td>
                            <td>{{ item.symbol }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </form>
    </div>

</div>
<script>
    // 点击按钮触发文件选择框
    document.getElementById("select-file-button").addEventListener("click", function() {
        document.getElementById("file-input").click();
    });

    // 处理文件选择事件
    function handleFileChange(event) {
        // 获取选择的文件
        const file = event.target.files[0];

        if (file) {
            const formData = new FormData();
            formData.append('type', "upload_file")
            formData.append('file', file);  // 将文件添加到FormData对象中

            // 使用 POST 请求将文件传递给后端
            fetch('/index/warehouse_func/', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                window.location.reload();
            })
            .catch(error => {
                ;
            });
        }
    }
</script>

{% endblock %}





























